package com.hendraanggrian.appcompat.widget;

import ohos.agp.components.AttrSet;
import ohos.agp.components.ListContainer;
import ohos.agp.components.TextField;
import ohos.app.Context;
import java.util.List;
import java.util.regex.Pattern;

/**
 * {@link TextField} with hashtag, mention, and hyperlink support.
 *
 * @see SocialView
 */
public class SocialEditText extends TextField implements SocialView {
    private final SocialView helper;

    public SocialEditText(Context context) {
        this(context, null);
    }

    public SocialEditText(Context context, AttrSet attrs) {
        super(context, attrs);
        helper = SocialViewHelper.install(this);
    }

    /**
     * hashTag规则
     *
     * @return hashTag规则
     */
    @Override
    public Pattern getHashtagPattern() {
        return helper.getHashtagPattern();
    }

    /**
     * Mention规则
     *
     * @return Mention规则
     */
    @Override
    public Pattern getMentionPattern() {
        return helper.getMentionPattern();
    }

    /**
     * link规则
     *
     * @return link规则
     */
    @Override
    public Pattern getHyperlinkPattern() {
        return helper.getHyperlinkPattern();
    }

    /**
     * 设置hashTag规则
     *
     * @param pattern 正则
     */
    @Override
    public void setHashtagPattern(Pattern pattern) {
        helper.setHashtagPattern(pattern);
    }

    /**
     * 设置Mention规则
     *
     * @param pattern 正则
     */
    @Override
    public void setMentionPattern(Pattern pattern) {
        helper.setMentionPattern(pattern);
    }

    /**
     * 设置link规则
     *
     * @param pattern 正则
     */
    @Override
    public void setHyperlinkPattern( Pattern pattern) {
        helper.setHyperlinkPattern(pattern);
    }

    /**
     * 是否为Hashtag
     *
     * @return 是/否
     */
    @Override
    public boolean isHashtagEnabled() {
        return helper.isHashtagEnabled();
    }

    /**
     * 是否为Mention
     *
     * @return 是/否
     */
    @Override
    public boolean isMentionEnabled() {
        return helper.isMentionEnabled();
    }

    /**
     * 是否为link
     *
     * @return 是/否
     */
    @Override
    public boolean isHyperlinkEnabled() {
        return helper.isHyperlinkEnabled();
    }

    /**
     * 设置属性
     *
     * @param enabled 是/否
     */
    @Override
    public void setHashtagEnabled(boolean enabled) {
        helper.setHashtagEnabled(enabled);
    }

    /**
     * 设置属性
     *
     * @param enabled 是/否
     */
    @Override
    public void setMentionEnabled(boolean enabled) {
        helper.setMentionEnabled(enabled);
    }

    /**
     * 设置属性
     *
     * @param enabled 是/否
     */
    @Override
    public void setHyperlinkEnabled(boolean enabled) {
        helper.setHyperlinkEnabled(enabled);
    }


    /**
     * 设置点击事件
     *
     * @param listener The callback that will run.
     */
    @Override
    public void setOnHashtagClickListener( SocialView.OnClickListener listener) {
        helper.setOnHashtagClickListener(listener);
    }

    /**
     * 设置点击事件
     *
     * @param listener The callback that will run.
     */
    @Override
    public void setOnMentionClickListener( SocialView.OnClickListener listener) {
        helper.setOnMentionClickListener(listener);
    }

    /**
     * 设置点击事件
     *
     * @param listener The callback that will run.
     */
    @Override
    public void setOnHyperlinkClickListener( SocialView.OnClickListener listener) {
        helper.setOnHyperlinkClickListener(listener);
    }

    /**
     * 设置监听事件
     *
     * @param listener The callback that will run.
     */
    @Override
    public void setHashtagTextChangedListener( OnChangedListener listener) {
        helper.setHashtagTextChangedListener(listener);
    }

    /**
     * 设置监听事件
     *
     * @param listener The callback that will run.
     */
    @Override
    public void setMentionTextChangedListener( OnChangedListener listener) {
        helper.setMentionTextChangedListener(listener);
    }

    /**
     * 输入框Hashtags字符串
     *
     * @return 字符串
     */
    @Override
    public List<String> getHashtags() {
        return helper.getHashtags();
    }

    /**
     * 输入框Mention字符串
     *
     * @return 字符串
     */
    @Override
    public List<String> getMentions() {
        return helper.getMentions();
    }

    /**
     * 输入框links字符串
     *
     * @return 字符串
     */
    @Override
    public List<String> getHyperlinks() {
        return helper.getHyperlinks();
    }

    /**
     * 输入内容
     *
     * @param text 内容
     * @return null
     */
    @Override
    public CharSequence terminateToken(CharSequence text) {
        return text;
    }

    /**
     * 开始输入的位置
     *
     * @param text 内容
     * @param cursor 光标位置
     * @param listContainer listContainer
     * @return 开始输入的位置
     */
    @Override
    public int findTokenStart(CharSequence text, int cursor, ListContainer listContainer) {
        return 0;
    }
}